Skip to content

chore(router): trim dependencies by inlining small single-use helpers - #8975

Open
gioboa wants to merge 1 commit into
QwikDev:mainfrom
gioboa:chore/router-trim-deps
Open

chore(router): trim dependencies by inlining small single-use helpers#8975
gioboa wants to merge 1 commit into
QwikDev:mainfrom
gioboa:chore/router-trim-deps

Conversation

@gioboa

@gioboa gioboa commented Aug 27, 2026

Copy link
Copy Markdown
Member

What

Several dependencies of @qwik.dev/router are used for a single function call. This PR replaces them with verbatim vendored copies of the upstream sources and removes dead dev-dependencies. It also drops magic-string entirely from the workspace (including as a runtime dependency of @qwik.dev/core).

Result: router goes from 26 → 17 direct dependencies, and core sheds magic-string. Every app installs fewer packages and ~3MB less node_modules. No behavior changes, no client-bundle impact.

How

Policy: pure copy/paste or nothing — no minimal reimplementations to maintain. Each vendored file carries a header with the source package, version, license, and upstream URL; the only edits are TypeScript type annotations. That keeps behavior byte-for-byte identical to what the dependency did (GitHub anchor ids, cookie parsing edge cases, NO_COLOR/TTY detection, ESTree serialization of bigint/RegExp/Map/Set/cycles).

Removed Was used for Replaced by
marked (932KB) parsing menu.md remark-parse, already installed via @mdx-js/mdx
@azure/functions (472KB) 3 type imports minimal vendored types (same public API shape)
github-slugger heading anchor ids verbatim copy incl. its generated character-class regex (slugger.ts + slugger-regex.ts)
estree-util-value-to-estree frontmatter → ESTree verbatim copy of the full upstream TS source (value-to-estree.ts)
set-cookie-parser one parseString call verbatim copy of the parseString path (parse-set-cookie.ts)
hast-util-to-string, hast-util-heading-rank text/heading helpers verbatim copies (hast-util-to-string.ts, hast-util-heading-rank.ts)
kleur 5 color functions in SSG logs verbatim copy of kleur/colors (kleur-colors.ts)
magic-string two literal string replacements plain String.replace in qwik-vite (manifest injection) and the docs REPL build; the transform now returns a null sourcemap for the manifest module, and function replacers fix latent $-pattern expansion
@types/mdx, mdast-util-mdx unused / type-only removed / moved to devDependencies

Dev-dependency cleanup: dropped uvu (asserts migrated to vitest), tsm (unused), @types/refractor (empty stub), @types/set-cookie-parser.

Verification

  • ✅ 536 router + qwik-vite unit tests pass, including 3 suites for the vendored helpers (updated to assert upstream behavior, e.g. github-slugger's no-trim slugs and set-cookie-parser's unknown-attribute passthrough)
  • tsc.check clean, eslint clean on all touched files
  • ✅ Built optimizer.mjs contains zero magic-string references; lockfile refreshed (13 packages removed)

Kept on purpose

source-map, unified, vfile, unist-util-visit are directly imported but already installed via @mdx-js/mdx — removing them saves nothing and creates phantom deps. mlly, yaml, csstype, launch-editor, and the remaining deps are real features, public-API types, or not worth the correctness risk.

Bigger wins (zod+valibot ~4.2MB, refractor+svgo ~4.5MB as optional peers) are possible but breaking — left for a separate discussion.

@gioboa
gioboa requested review from a team as code owners August 27, 2026 19:23
@changeset-bot

changeset-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 29e94c3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@qwik.dev/router Patch
@qwik.dev/core Patch
eslint-plugin-qwik Patch
@qwik.dev/devtools Patch
@qwik.dev/react Patch
@qwik.dev/utils Patch
create-qwik Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@maiieul maiieul moved this to Waiting For Review in Qwik Development Aug 27, 2026
@gioboa
gioboa force-pushed the chore/router-trim-deps branch 2 times, most recently from a907dfd to 406fb4c Compare August 27, 2026 19:31
@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8975

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8975

@qwik.dev/utils

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/utils@8975

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8975

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8975

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8975

@qwik.dev/devtools

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/devtools@8975

commit: 29e94c3

@gioboa gioboa changed the title chore(router): drop eight dependencies by inlining small helpers chore(router): trim dependencies by inlining small single-use helpers Aug 27, 2026
@gioboa
gioboa force-pushed the chore/router-trim-deps branch 2 times, most recently from d12e906 to ec9aada Compare August 27, 2026 20:04
@gioboa
gioboa enabled auto-merge August 27, 2026 20:11
@gioboa
gioboa force-pushed the chore/router-trim-deps branch from ec9aada to b5fca24 Compare August 27, 2026 20:24
@gioboa gioboa changed the title chore(router): trim dependencies by inlining small single-use helpers chore: trim router and core dependencies by inlining small single-use helpers Aug 27, 2026

@maiieul maiieul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm this looks good. Thanks @gioboa! Will make maintaining deps easier for sure 👍 Can you add a small comment on each vendor helper that says which vendor it was copied from? This way it reduces the likelihood for a future PR, especially with AI, to introduce a bug into those.

@gioboa

gioboa commented Aug 28, 2026

Copy link
Copy Markdown
Member Author

Good idea @maiieul 👍

@gioboa
gioboa force-pushed the chore/router-trim-deps branch from b5fca24 to 630ca10 Compare August 28, 2026 17:40

@maiieul maiieul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic-string impl says "minimal replacement". Copied source code is good but half baked AI impl is risky. Let's remove it please.

@gioboa gioboa changed the title chore: trim router and core dependencies by inlining small single-use helpers chore(router): trim dependencies by inlining small single-use helpers Aug 29, 2026
@gioboa

gioboa commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

Fair enough 👍 Reverted the custom literal-replace helper — magic-string is back for the manifest injection, bumped to the maintained v1 line (1.2.3, pure-ESM only, no API change). PR description updated accordingly; the rest of the vendored helpers stay as reviewed.

@gioboa
gioboa force-pushed the chore/router-trim-deps branch from 630ca10 to 766741d Compare August 29, 2026 19:58
@gioboa
gioboa requested a review from maiieul August 29, 2026 20:01
@gioboa
gioboa force-pushed the chore/router-trim-deps branch 2 times, most recently from 8603537 to 6eb2657 Compare August 31, 2026 20:48
@gioboa
gioboa force-pushed the chore/router-trim-deps branch from 6eb2657 to 29e94c3 Compare September 1, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting For Review

Development

Successfully merging this pull request may close these issues.

2 participants